Fail fast on mixed id types for mongo connector. - #382
Conversation
📝 WalkthroughWalkthroughDuring initial sync plan generation, the code now computes both the smallest and largest Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@connectors/mongo/conn.go`:
- Around line 260-270: The _id type validation currently checks the entire
collection but the sync read path uses the filtered query (c.query), so change
the validation to use the same filter scope: update findSmallestID and
findLargestID to accept a filter parameter (e.g., bson.D) and pass c.query (the
same filter used in the read path) when calling them from the validation block
that currently references partition.Namespace; ensure the implementations use
the provided filter in their Mongo queries so mixed _id types outside the filter
won't cause a false-positive error.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
| lowest, err := findSmallestID(ctx, col) | ||
| if err != nil { | ||
| return fmt.Errorf("err finding smallest id: %w", err) | ||
| } | ||
| high, err := findLargestID(ctx, col) | ||
| if err != nil { | ||
| return fmt.Errorf("err finding largest id: %w", err) | ||
| } | ||
| if !lowest.IsZero() && !high.IsZero() && lowest.Type != high.Type { | ||
| return fmt.Errorf("mixed _id types not supported in %v: found %v and %v", partition.Namespace, lowest.Type, high.Type) | ||
| } |
There was a problem hiding this comment.
Fail-fast mixed _id validation should use the same filter scope as sync reads.
At Line 260-Line 270, _id type validation runs on the full collection, while read path filtering uses c.query (Line 460-Line 463). This can fail planning for a valid filtered sync if mixed types exist outside the filter.
Proposed fix
- lowest, err := findSmallestID(ctx, col)
+ planFilter := bson.D{}
+ if len(c.query) > 0 {
+ planFilter = append(planFilter, c.query...)
+ }
+ lowest, err := findSmallestID(ctx, col, planFilter)
if err != nil {
return fmt.Errorf("err finding smallest id: %w", err)
}
- high, err := findLargestID(ctx, col)
+ high, err := findLargestID(ctx, col, planFilter)
if err != nil {
return fmt.Errorf("err finding largest id: %w", err)
}// Update helpers to accept a filter:
func findSmallestID(ctx context.Context, col *mongo.Collection, filter bson.D) (bson.RawValue, error)
func findLargestID(ctx context.Context, col *mongo.Collection, filter bson.D) (bson.RawValue, error)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@connectors/mongo/conn.go` around lines 260 - 270, The _id type validation
currently checks the entire collection but the sync read path uses the filtered
query (c.query), so change the validation to use the same filter scope: update
findSmallestID and findLargestID to accept a filter parameter (e.g., bson.D) and
pass c.query (the same filter used in the read path) when calling them from the
validation block that currently references partition.Namespace; ensure the
implementations use the provided filter in their Mongo queries so mixed _id
types outside the filter won't cause a false-positive error.
Summary by CodeRabbit
Bug Fixes
Performance